package com.example.cloud.controller.business.reservation;

import com.alibaba.fastjson.JSON;
import com.example.cloud.controller.common.BaseController;
import com.example.cloud.model.business.reservation.Patient;
import com.example.cloud.model.dto.QueryModel;
import com.example.cloud.model.dto.Result;
import com.example.cloud.service.business.reservation.PatientService;
import com.example.cloud.utils.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by wangtao on 2018/1/26.
 */
@RestController
@RequestMapping("/patient")
public class PatientController extends BaseController {

	private Logger logger = LoggerFactory.getLogger(PatientController.class);

	@Autowired
	private PatientService patientService;

	@PostMapping("/search")
	public Result search(@RequestBody QueryModel model) {
		return this.singleQuery(model, Patient.class);
	}

	@GetMapping("/findById/{id}")
	public Result findById(@PathVariable Long id) {
		return ResultUtil.success(JSON.parse(JSON.toJSONString(patientService.findOne(id))));
	}

	@GetMapping("/findByMedicalNumber")
	public Result findByMedicalNumber(@RequestParam("medicalNumber") String medicalNumber) {
		return ResultUtil.success(patientService.findByMedicalNumber(medicalNumber));
	}
	
	@PostMapping("/saveOrUpdate")
	public void saveOrUpdate(@RequestBody Patient record) {
		patientService.doSave(record);
	}

	@PostMapping("/delete")
	public void delete(@RequestBody List<Long> ids) {
		patientService.doDelete(ids);
	}

	@PostMapping("/setHealthCare")
	public void setHealthCare(@RequestBody Patient patien) {
		patientService.doSetHealthCare(patien);
	}

	@GetMapping("/checkPhone/{phone}")
	public Result checkPhone(@PathVariable String phone) {
		return ResultUtil.success(patientService.doCheckPhone(phone));
	}

	@PostMapping("/confirm")
	public void confirm(@RequestBody Patient record) {
		patientService.doConfirm(record);
	}

}
